package com.huawei.appmarket.framework.widget;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Handler;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.card.base.bean.KeywordInfo;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.search.api.ISearchActivityProtocol;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import huawei.widget.HwSearchView;
import java.util.LinkedHashMap;
import o.bus;
import o.dge.d;
import o.dgh;
import o.dgm;
import o.djn;
import o.djo;
import o.dof;
import o.ContentManager;
import o.dyk;
import o.ehm;
import o.ety;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;
import o.fiu;
import o.fjb;
import o.ll;

public class FixedSearchView extends LinearLayout {
    private final BroadcastReceiver ʻ = new 2(this);
    private String ʼ;
    private String ʽ;
    private boolean ˊ = false;
    private Context ˋ;
    private BaseTitleBean ˋॱ;
    private long ˎ = 0;
    @SuppressLint({"HandlerLeak"})
    protected Handler ˏ = new 5(this);
    private String ˏॱ;
    private HwSearchView ॱ;
    private View ॱˊ;
    private djn ॱॱ;
    private KeywordInfo ᐝ;

    public FixedSearchView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˋ = context;
        ˋ();
        ˏ();
    }

    public FixedSearchView(Context context) {
        super(context);
        this.ˋ = context;
        ˋ();
        ˏ();
    }

    private static LinkedHashMap<String, String> ˎ(Context context, String str, String str2) {
        Activity activity;
        LinkedHashMap<String, String> linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("trace", str);
        linkedHashMap.put("homepagetabid", str2);
        if (context instanceof Activity) {
            activity = (Activity) context;
        } else {
            context = null;
        }
        linkedHashMap.put("service_type", String.valueOf(dgm.ˎ(activity)));
        return linkedHashMap;
    }

    public static final String ˎ() {
        return ContentManager.getInstant().getContext().getPackageName() + ".framework.widget.SearchBar.Recycle";
    }

    public BaseTitleBean ॱ() {
        return this.ˋॱ;
    }

    public void setTitleBean(BaseTitleBean baseTitleBean) {
        this.ˋॱ = baseTitleBean;
    }

    public void setIsFromForum(boolean z) {
        this.ˊ = z;
        if (this.ॱ != null && z) {
            this.ॱ.setQueryHint(getResources().getString(n.יˋ));
        }
    }

    private void ˏ() {
        if (this.ˋ instanceof djo) {
            ll.ˏ(getContext()).ˏ(this.ʻ, new IntentFilter(ˎ()));
            this.ॱॱ = ((djo) this.ˋ).ॱʻ();
            if (this.ॱॱ != null) {
                if (this.ॱॱ.ॱ() == null) {
                    ॱ(this.ॱॱ.ˏ(), false);
                } else {
                    ॱ(this.ॱॱ.ॱ(), true);
                }
                this.ॱॱ.ॱ(5000);
            }
        }
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        return true;
    }

    private void ॱ(KeywordInfo keywordInfo, boolean z) {
        if (this.ॱ != null && !this.ˊ) {
            CharSequence charSequence;
            this.ᐝ = keywordInfo;
            if (this.ᐝ == null) {
                charSequence = "";
            } else {
                charSequence = this.ᐝ.ॱ();
            }
            if (dof.ˋ(charSequence)) {
                this.ॱ.setQueryHint(getResources().getString(n.ˊߵ));
                return;
            }
            this.ॱ.setQueryHint(charSequence);
            if (this.ॱॱ != null && this.ॱॱ.ˎ(z) && this.ᐝ != null) {
                dyk.ॱ(this.ˋ, String.valueOf(this.ॱ.getId()), this.ᐝ.ˋ());
            }
        }
    }

    private void ˋ() {
        this.ॱˊ = LayoutInflater.from(this.ˋ).inflate(h.ˡ, this);
        this.ॱˊ.setOnClickListener(new 3(this));
        this.ॱ = (HwSearchView) this.ॱˊ.findViewById(j.ﹺॱ);
        LinearLayout linearLayout = (LinearLayout) this.ॱ.findViewById(j.ʻᶫ);
        if (linearLayout != null) {
            linearLayout.setPadding(0, 0, 0, 0);
        }
        EditText editText = (EditText) this.ॱ.findViewById(j.ʼՙ);
        if (editText != null) {
            editText.setImportantForAccessibility(2);
        }
        this.ॱ.setQueryHint(getResources().getString(n.ˊߵ));
        this.ॱ.setContentDescription(getResources().getString(n.ˊי));
        ehm.ˎ(getContext(), this.ॱ);
    }

    private void ˊ() {
        String str;
        BaseTitleBean ॱ = ॱ();
        if (ॱ != null) {
            String ˏ = ॱ.ˏ();
            this.ʼ = "homepage".equals(ॱ.ॱ()) ? ॱ.ˊ() : null;
            this.ˏॱ = ॱ.ˋ();
            str = ˏ;
        } else {
            str = null;
        }
        this.ʽ = this.ʼ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˏॱ;
        dgh.onEvent(new d(getContext(), n.ˊʻ).ˏ("01|" + this.ʽ).ˋ());
        dgh.ˋ("searchbar_click", ˎ(getContext(), str, this.ʼ));
        if (this.ˊ) {
            fjb ˎ = fho.ˏ().ˋ("Search").ˎ("Search");
            ISearchActivityProtocol iSearchActivityProtocol = (ISearchActivityProtocol) ˎ.ˊ();
            iSearchActivityProtocol.setNotRequestHotWord(true);
            iSearchActivityProtocol.setNotRequestAuto(true);
            iSearchActivityProtocol.setTraceId(this.ʼ);
            iSearchActivityProtocol.setScheme("searchForum|");
            iSearchActivityProtocol.setIntentKeyword(null);
            iSearchActivityProtocol.setHintValue(getResources().getString(n.יˋ));
            iSearchActivityProtocol.setDomainId(((bus) fho.ˏ().ˋ("Forum").ॱ(bus.class)).ˎ());
            iSearchActivityProtocol.setForumSearch(true);
            iSearchActivityProtocol.setFromMain(true);
            fiu.ˊ().ˏ(getContext(), ˎ);
        } else if (this.ᐝ == null || TextUtils.isEmpty(this.ᐝ.ॱ())) {
            ety.ˊ().ॱ(getContext(), this.ʼ, null);
        } else {
            ety.ˊ().ॱ(getContext(), this.ʼ, true, false, this.ᐝ);
        }
    }

    public void setTabInfo(String str, String str2) {
        this.ʼ = str;
        this.ˏॱ = str2;
    }

    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
    }

    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        ll.ˏ(getContext()).ˋ(this.ʻ);
    }
}
